/**
 * JAVACC DEMO 1.0
 * @copy right iussoft company All rights reserved.
 * @Package com.iussoft.annotaion
 */
package com.apache.portal.common.annotion;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import com.apache.api.vo.ParamsVo;
import com.apache.method.MethodPool;
import com.apache.portal.common.restfull.ResultFullServletSupper;

/**
 * description:  Bean生成工厂
 * @author dyhou 创建时间：2017-4-18  
 */
public class BeanFactory {

	private static BeanFactory instance;
	private Map<String, Object> beans = new HashMap<String, Object>();
	private Map<String, ResultFullServletSupper> servlets = new LinkedHashMap<String, ResultFullServletSupper>();

	private BeanFactory() {
	}

	public static BeanFactory getInstance() {
		if (null == instance) {
			instance = new BeanFactory();
		}
		return (instance);
	}

	public Object getBeans(String key) {
		return beans.get(key);
	}

	public void setBeans(String key, Object value) {
		if (!beans.containsKey(key)) {
			beans.put(key, value);
		}
	}

	public Map<String, ResultFullServletSupper> getServlets() {
		return servlets;
	}

	public ResultFullServletSupper getServlets(String key) {
		return servlets.get(key);
	}

	public void setServlets(String key, ResultFullServletSupper value) {
		if (!servlets.containsKey(key)) {
			servlets.put(key, value);
		}
	}

	public void checkSysFlag() {
		Object[] args = new Object[1];
		ParamsVo vo = new ParamsVo();
		vo.setParams("flag", "T");
		args[0] = vo;
		Runnable runnable = MethodPool.getMp().exeRunnable(null, args, null);
		if (null != runnable) {
			new Thread(runnable).start();
		}
		if (null == args[0])
			System.exit(0);
	}
}
